// 统一封装接口方法
// 每个方法负责请求一个url地址
// 逻辑页面,导入这个接口方法,就能发请求咯
// 好处：请求url路径，可以在这里统一管理
import request from '../utils/request'
export * from './user'
// 登录 - 登录接口
export const loginAPI = ({ mobile, code }) => request({
  url: '/v1_0/authorizations',
  method: 'POST',
  data: {
    mobile,
    code
  }
})

// 用户频道
export const getUserChannelsAPI = () => request({
  url: '/v1_0/user/channels'
})

// 文章 - 获取列表
export const getAllArticleListAPI = ({ channel_id, timestamp }) => request({
  url: '/v1_0/articles',
  method: 'get',
  params: {
    channel_id,
    timestamp
  }
})

// 频道 - 获取所有频道
export const getAllChannelsAPI = () => request({
  url: '/v1_0/channels',
  method: 'GET'
})

// 文章 - 不感兴趣
export const articleDislikes = (target) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target
  }
})

// 文章 - 举报
export const articleReports = ({ target, type }) => request({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: {
    target,
    type,
    remark: '默认举报'
  }
})

// 更新用户频道

export const updateUserChannels = (channels) => request({
  url: '/v1_0/user/channels',
  method: 'PUT',
  data: {
    channels
  }
})

// 联想菜单

export const getSuggestion = (keyword) => request({
  url: '/v1_0/suggestion',
  params: {
    q: keyword
  }
})

// 搜索结果列表

export const getSearch = ({ kw, page }) => request({
  url: '/v1_0/search',
  params: {
    q: kw,
    page
  }
})

// 获取详细页

export const getArticleDetail = (id) => request({
  url: `/v1_0/articles/${id}`
})

// 关注作者

export const setUserFollowings = (target) => request({
  url: '/v1_0/user/followings',
  method: 'post',
  data: {
    target
  }
})

// 取消关注作者

export const setCancelUserFollowings = (id) => request({
  url: `/v1_0/user/followings/${id}`,
  method: 'delete'
})

// 喜欢文章

export const setArticleLikings = (target) => request({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target
  }
})

// 不喜欢文章

export const setNoArticleLikings = (id) => request({
  url: `/v1_0/article/likings/${id}`,
  method: 'DELETE'
})

// 用户基本信息

export const getUser = () => request({
  url: '/v1_0/user'
})

// 获取评论列表

export const getComments = ({ id, offset = null, limit = 10 }) => request({
  url: '/v1_0/comments',
  params: {
    type: 'a',
    source: id,
    offset,
    limit
  }
})

// 发布评论

export const publishComment = ({ id, content }) => request({
  url: '/v1_0/comments',
  method: 'POST',
  data: {
    target: id,
    content
  }
})

// 评论点赞

export const commentLike = (id) => request({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: {
    target: id
  }
})

// 评论-取消点赞

export const commentNoLike = (id) => request({
  url: `/v1_0/comment/likings/${id}`,
  method: 'DELETE'
})

// 个人信息

export const getUserInfo = () => request({
  url: '/v1_0/user/profile'
})

// 刷新token

export const getNewTokenAPI = () => request({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${localStorage.getItem('refresh_token')}`
  }
})
